define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'uplevel/index' + location.search,
                    add_url: 'uplevel/add',
                    edit_url: 'uplevel/edit',
                    del_url: 'uplevel/del',
                    multi_url: 'uplevel/multi',
                    table: 'uplevel',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'uplevel.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3'),"4":__('Level 4'),"5":__('Level 5')}, formatter: Table.api.formatter.normal},
                        {field: 'true_num', title: __('True_num')},
                        {field: 'team_st', title: __('Team_st')},
                        // {field: 'cb_mill_id', title: __('Cb_mill_id')},

                        {field: 'have.name', title: __('have.name')},
                        {field: 'have.image', title: __('have.image'),operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'up_level_num', title: __('Up_level_num')},
                        {field: 'share_fee', title: __('Share_fee'), operate:'BETWEEN'},
                        {field: 'weight_fee', title: __('Weight_fee'), operate:'BETWEEN'},
                        // {field: 'zeng_mill_id', title: __('Zeng_mill_id')},
                        // {field: 'zeng_mill_num', title: __('Zeng_mill_num')},
                        {field: 'send.name', title: __('send.name')},
                        {field: 'send.image', title: __('send.image'),operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},


                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});